<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>权限管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/lib/layui-v2.5.5/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <input type="hidden" name="id" th:value="${model.id}">
    <input type="hidden" id="oldEnableStatus" th:value="${model.enableStatus}">
    <div class="layui-form-item">
        <label class="layui-form-label required">应用名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" maxlength="60" lay-reqtext="名称不能为空" placeholder="请输入应用名称" value="" class="layui-input" th:value="${model.name}">
            <tip>填写应用的名称。</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">应用编码</label>
        <div class="layui-input-block">
            <input type="text" name="code" lay-verify="required" maxlength="8" lay-reqtext="应用编码不能为空" placeholder="请输入应用编码" value="" class="layui-input" th:value="${model.code}">
            <tip>填写应用的编码(应用编码只允许字母、数字、下划线组成,长度1-8位)</tip>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">应用状态</label>
        <div class="layui-input-block" th:if="${model.enableStatus eq 1}" >
            <input type="radio" name="enableStatus" value="1" title="启用" checked>
            <input type="radio" name="enableStatus" value="0" title="禁用">
        </div>
        <div class="layui-input-block" th:if="${model.enableStatus eq 0}" >
            <input type="radio" name="enableStatus" value="1" title="启用" >
            <input type="radio" name="enableStatus" value="0" title="禁用" checked>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">备注信息</label>
        <div class="layui-input-block">
            <textarea name="remark" class="layui-textarea" maxlength="255" placeholder="请输入备注信息" th:value="${model.remark}"></textarea>
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
<script th:src="@{/lib/layui-v2.5.5/layui.js}" charset="utf-8"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        function updateForm(data)
        {
            $.ajax({
                url: "[[@{/app/update}]]",
                contentType: "application/json; charset=utf-8",
                type: 'POST',
                data: JSON.stringify(data.field),
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg);
                        return false;
                    }
                    var index = layer.alert(data.msg, {
                        title: '提示信息'
                    }, function () {
                        // 关闭弹出层
                        layer.close(index);
                        var iframeIndex = parent.layer.getFrameIndex(window.name);
                        parent.location.reload();
                        parent.layer.close(iframeIndex);

                    });
                }
            });
        }


        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var currentEnableStatus = data.field.enableStatus;
            var oldEnableStatus = $("#oldEnableStatus").val();
            if(currentEnableStatus!=oldEnableStatus)
            {
                if(currentEnableStatus=="0")
                {
                    layer.confirm('将不能登录和操作该应用,确定要禁用吗?', function (index) {
                        return updateForm(data);
                    });
                }else{
                    return updateForm(data);
                }
            }else {
                return updateForm(data);
            }
            return false;
        });

    });
</script>
</body>
</html>